package cn.com.bluemoon.daps.api.model;

import cn.com.bluemoon.daps.api.model.factory.RemoteDataModelTableServiceFallbackFactory;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiModel;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.model.dto.DapDataModelTableDto;
import cn.com.bluemoon.daps.model.entity.DapDataModelTable;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author Jarod.Kong
 * @date 2020/12/22 9:07
 */
@FeignClient(value = DapsApiModel.SERVICE, fallbackFactory = RemoteDataModelTableServiceFallbackFactory.class)
@RequestMapping(DapsApiModel.BASE_URI + DapsApiModel.API_MODEL_TABLE)
@ApiIgnore
public interface RemoteDataModelTableService {
    @PostMapping("/list")
    @ApiOperation("模型id+是否已发布，获取模型表")
    List<DapDataModelTableDto> getTablePublishInfos(@RequestParam("modelId") String modelId, @RequestParam("isPublish") int isPublish);

    @PostMapping("/updateTable")
    @ApiOperation(("根据id表信息"))
    ResultBean<Boolean> updateById(@RequestParam("tableId") String id,
                                   @RequestBody DapDataModelTable newTable);

    @DeleteMapping("/deleteTable")
    @ApiOperation(("根据id字段信息"))
    ResultBean<Boolean> removeById(@RequestParam("tableId") String id);

    @PostMapping("/saveTable")
    @ApiOperation(("根据id字段信息"))
    ResultBean<String> saveTable(@RequestBody DapDataModelTable newTable);

    @GetMapping("/listByModelAndNewst")
    @ApiOperation(("获取模型表列表"))
    ResultBean<List<DapDataModelTable>> listByModelIdAndNewest(@RequestParam("modelId") String modelId,
                                                         @RequestParam(value = "newest", defaultValue = "true") boolean newest);

    @GetMapping("save/updateTime")
    @ApiOperation(("开发库导入模型，加*调用"))
    ResultBean<Boolean> updateTableTime(@RequestParam("modelId") String modelId, @RequestParam("tableId") String tableId);

    @GetMapping("/get/topic/table")
    @ApiOperation(value = "查询主题是否被模型表引用")
    ResultBean<Boolean> getTopicTable(@RequestParam("topicId") String topicId);

    @PostMapping("/get/table/list")
    @ApiOperation(value = "根据多个id获取表信息")
    ResultBean<List<DapDataModelTable>> getTableList(@RequestBody List<String> tableIds);

    @GetMapping("/get/table/field")
    @ApiOperation(("获取模型表和字段id"))
    ResultBean<List<String>> findTableInfo(@RequestParam("modelId") String modelId, @RequestParam("tableName") String tableName, @RequestParam("fieldName") String fieldName);
}
